package cryptography

import (
    "crypto/md5"
    "fmt"
    "io"
    "os"
)

func FileMd5(path string) (string, error) {
    f, err := os.Open(path)
    if err != nil {
        fmt.Println("[MD5]Open", err)
        return "", err
    }

    defer f.Close()

    md5hash := md5.New()
    if _, err := io.Copy(md5hash, f); err != nil {
        fmt.Println("[MD5]Copy", err)
        return "", err
    }

    return fmt.Sprintf("%x\n", md5hash.Sum(nil)), nil
}
